<template>
	<div class="regBox" v-if="is_show">
		<div class="regBox_pub"></div>
		<div class="regBox_main">
			<b>{{$t('h_forgetBox.title1')}}</b>
			<div class="forms">
				<el-input :placeholder="$t('h_forgetBox.title2')" v-model="formData.username">
					<i slot="prefix" class="el-input__icon el-icon-s-custom"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				<el-input :placeholder="$t('h_forgetBox.title3')" v-model="formData.pay_password">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				<el-input :placeholder="$t('h_forgetBox.title4')" v-model="formData.password">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				<el-input :placeholder="$t('h_forgetBox.title5')" v-model="formData.password_cp">
					<i slot="prefix" class="el-input__icon el-icon-s-finance"
						style="color: var(--theme-text-color-lighten);"></i>
				</el-input>
				<button class="submit" @click="submit">{{$t('h_forgetBox.title6')}}</button>
			</div>
			<div class="closeBtn" @click="closeForget">
				
			</div>
		</div>
		
		
	</div>
</template>

<script>
	export default {
		data() {
			return {
				is_show:false,
				step:0,
				checked:true,
				formData: {
					username: '',
					password: '',
					password_cp: ''
				}
			};
		},
		methods: {
			submit(){
				if(!this.formData.username) return this.$message(this.$t('h_forgetBox.title7'));
				let reg =/^[a-zA-Z\d]\w{4,7}[a-zA-Z\d]$/;
				let re = new RegExp(reg)
				if(!this.formData.password || !this.formData.password_cp) return this.$message(this.$t('h_forgetBox.title8'));
				if(this.formData.password != this.formData.password_cp) return this.$message(this.$t('h_forgetBox.title9'));
				let reg1 =/^[a-zA-Z\d]\w{4,14}[a-zA-Z\d]$/;
				let re1 = new RegExp(reg);
				if(!re1.test(this.formData.password)) return this.$message(this.$t('h_forgetBox.title10'));
				
				this.$parent.openverifyBox((code,key)=>{
					this.formData.code = code
					this.formData.key = key
					const loading = this.$loading({
					    lock: true,
					    text: 'Loading',
					    spinner: 'el-icon-loading',
					    background: 'rgba(0, 0, 0, 0.7)'
					});
					this.$api.Loginforget(this.formData,(res)=>{
						loading.close();
						if(res.code == 0){
							this.$parent.reloadUserInfo();
							this.closeForget()
							this.$message.success(res.msg);
						}else{
							this.$message.error(res.msg);
						}
					})
				})
				
			},
			openForget(){
				this.is_show = true
			},
			closeForget(){
				this.is_show = false
			},
		}
	}
</script>

<style lang="less" scoped>
	.regBox {
		position: fixed;
		z-index: 1000;
		width: 100vw;
		height: 100vh;
		overflow-y: overlay;
		top:0;
		left: 0;
		
		.closeBtn{
			position: absolute;
			border-radius: 50%;
			z-index: 3;
			bottom: -.9rem;
			left: 0;
			right: 0;
			margin: auto;
			width: 0.5984rem;
			height: 0.5984rem;
			background-image: url(/icons/main.png);
			background-position: -5.1136rem -4.2024rem;
			background-size: 8.296rem 7.7928rem;
		}
		&_pub {
			position: fixed;
			z-index: 1;
			width: 100vw;
			height: 100vh;
			width: 100vw;
			height: 100vh;
			background: rgba(0, 0, 0, .6);
		}

		&_main {
			position: absolute;
			z-index: 2;
			background-color: var(--theme-main-bg-color);
			border: thin solid;
			border-color: var(--theme-color-line);
			border-radius: 0.2rem;
			position: absolute;
			top: 26vh;
			left: 0;
			right: 0;
			width: 6rem;
			height: 6.5rem;
			margin: auto;

			.forms {
				max-height: 7rem;
				overflow-x: hidden;
				overflow-y: overlay;
				padding: 0 0.36rem;
				display: flex;
				flex-direction: column;
			}
			.el-input{
				margin: 0 0 .32rem;
			}
			p {
				font-size: .18rem;
				height: 0.4rem;
				line-height: 1;
				color: var(--theme-secondary-color-error);
				margin: .16rem 0 .06rem .16rem;
				opacity: .7;
			}

			b {
				margin: 0.2rem 0 0.4rem;
				color: var(--theme-text-color-darken);
				font-size: .32rem;
				font-weight: 700;
				height: 0.34rem;
				display: block;
				text-align: center;
			}
			.msg{
				display: flex;
				margin-bottom: .3rem;
				span{
					font-size: .26rem;
					color: var(--theme-text-color-lighten);
					margin: 0 0 0 .1rem ;
				}
				i{
					font-size: .26rem;
					font-style: normal;
					color: var(--theme-primary-color);
				}
			}
			.submit{
				background-color: var(--theme-primary-color);
				border-color: var(--theme-primary-color);
				border-radius: 0.14rem;
				height: .8rem;
				line-height: .8rem;
				display: block;
				color: var(--theme-primary-font-color);
				font-size: .24rem!important;
			}
			.aas{
				display: flex;
				margin: .3rem 0;
				span{
					flex: 1;
					display: block;
					text-align: center;
					font-size: .24rem;
					color: var(--theme-primary-color);
				}
			}
		}
	}
</style>